package com.ruoyi.project.poem.teacoinpackage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.poem.teacoinpackage.domain.TeacoinPackage;
import com.ruoyi.project.poem.teacoinpackage.service.ITeacoinPackageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 茶币充值套餐Controller
 * 
 * @author shixiangwen
 * @date 2020-04-28
 */
@Controller
@RequestMapping("/poem/teacoinpackage")
public class TeacoinPackageController extends BaseController
{
    private String prefix = "poem/teacoinpackage";

    @Autowired
    private ITeacoinPackageService teacoinPackageService;

    @RequiresPermissions("poem:teacoinpackage:view")
    @GetMapping()
    public String teacoinpackage()
    {
        return prefix + "/teacoinpackage";
    }

    /**
     * 查询茶币充值套餐列表
     */
    @RequiresPermissions("poem:teacoinpackage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TeacoinPackage teacoinPackage)
    {
        startPage();
        List<TeacoinPackage> list = teacoinPackageService.selectTeacoinPackageList(teacoinPackage);
        return getDataTable(list);
    }

    /**
     * 导出茶币充值套餐列表
     */
    @RequiresPermissions("poem:teacoinpackage:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TeacoinPackage teacoinPackage)
    {
        List<TeacoinPackage> list = teacoinPackageService.selectTeacoinPackageList(teacoinPackage);
        ExcelUtil<TeacoinPackage> util = new ExcelUtil<TeacoinPackage>(TeacoinPackage.class);
        return util.exportExcel(list, "teacoinpackage");
    }

    /**
     * 新增茶币充值套餐
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存茶币充值套餐
     */
    @RequiresPermissions("poem:teacoinpackage:add")
    @Log(title = "茶币充值套餐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TeacoinPackage teacoinPackage)
    {
        return toAjax(teacoinPackageService.insertTeacoinPackage(teacoinPackage));
    }

    /**
     * 修改茶币充值套餐
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TeacoinPackage teacoinPackage = teacoinPackageService.selectTeacoinPackageById(id);
        mmap.put("teacoinPackage", teacoinPackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存茶币充值套餐
     */
    @RequiresPermissions("poem:teacoinpackage:edit")
    @Log(title = "茶币充值套餐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TeacoinPackage teacoinPackage)
    {
        return toAjax(teacoinPackageService.updateTeacoinPackage(teacoinPackage));
    }

    /**
     * 删除茶币充值套餐
     */
    @RequiresPermissions("poem:teacoinpackage:remove")
    @Log(title = "茶币充值套餐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(teacoinPackageService.deleteTeacoinPackageByIds(ids));
    }
}
